package com.yskj.otms.controller;

import com.yskj.otms.services.IUserServices;
import net.sf.json.JSONObject;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


/**
 * Created by Administrator on 2019/1/8.
 */
@Controller
@RequestMapping("/user")
public class UserController {
    private static Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private IUserServices iUserServices;

    @RequestMapping("/userLogin")
    @ResponseBody
    public JSONObject userLogin(HttpServletRequest request)throws Exception{
        logger.info("UserController toLogin start");
        JSONObject loginObj = new JSONObject();
        try {
            loginObj = iUserServices.toLogin(request);
        } catch (Exception e) {
            logger.error("UserController toLogin Exception", e);
            loginObj.put("SUCCESS", false);
            loginObj.put("MSG","登录失败！");
        }
        return loginObj;
    }


    @RequestMapping("/getVerificationCode")
    @ResponseBody
    public JSONObject getVerificationCode(HttpServletRequest request)throws Exception{
        logger.info("UserController getVerificationCode start");
        JSONObject loginObj = new JSONObject();
        try {
            loginObj = iUserServices.getVerificationCode(request);
        } catch (Exception e) {
            logger.error("UserController getVerificationCode Exception", e);
            loginObj.put("SUCCESS", false);
            loginObj.put("MSG","获取验证码失败！");
        }
        return loginObj;
    }

}
